home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / egs-tools / egs_demo-version / egs_devels / examples / beginner_gadgets / gadget5.c < prev    next >
C/C++ Source or Header  |  1994-06-06  |  7KB  |  185 lines

  1. /**************************************************************************
  2. *****                       Gadget Demo 5                             *****
  3. *****                                                                 *****
  4. *****                     by John J. Karcher                          *****
  5. *****                                                                 *****
  6. *****                       10 August 1992                            *****
  7. *****                       10 Jan 1993 mvk                           *****
  8. *****                                                                 *****
  9. **************************************************************************/
  10.  
  11. /*
  12.    This program opens up a window with a three-by-three array of
  13.    gadgets, using egsgadbox.library.  To make it a little more
  14.    interesting, the gadgets are grouped into three groups of
  15.    equivalent gadgets each.  Try it; you'll see.
  16.  
  17.    This demonstrates how to use CreateHorizBox() and
  18.    CreateVertiBox() together to make gadget arrays.  It also
  19.    shows that gadget IDs can be used to your advantage.
  20. */
  21.  
  22. #include <stdio.h>
  23. #include <exec/types.h>
  24. #include <egs/egsintui.h>
  25. #include <egs/egsgadbox.h>
  26. #include <proto/exec.h>
  27. #include <egs/proto/all.h>
  28.  
  29.  
  30. #define  GAD_1_ID    1
  31. #define  GAD_2_ID    2
  32. #define  GAD_3_ID    3
  33.  
  34. BYTE  CreateWindow(void);
  35. BYTE  CreateGfx(void);
  36.  
  37. struct Library *EGSIntuiBase;
  38. struct Library *EGBBase;
  39.  
  40. struct EB_GadContextNode   *GadCon;
  41. struct EI_Window           *Win;
  42.  
  43.  
  44. BYTE  CreateGfx(void)
  45. {
  46.    EB_GadBoxPtr           root, b1, b2, b3;
  47.    BYTE  ret = 0;
  48.  
  49.    if (GadCon = EB_CreateGadContext(NULL, NULL, -1, -1))
  50.      {
  51.       root = EB_CreateVertiBox(GadCon);
  52.       EB_AddLastSon(root, EB_CreateVertiFill(GadCon, TRUE, 0));
  53.  
  54.       b1 = EB_CreateHorizBox(GadCon);
  55.       EB_AddLastSon(root, b1);
  56.       EB_AddLastSon(b1, EB_CreateHorizFill(GadCon, TRUE, 0));
  57.       EB_AddLastSon(b1, EB_CreateTextAction(GadCon, "_Leave Me Alone", GAD_2_ID, EB_FILL_ALL));
  58.       EB_AddLastSon(b1, EB_CreateHorizFill(GadCon, TRUE, 0));
  59.       EB_AddLastSon(b1, EB_CreateTextAction(GadCon, "_Help Me", GAD_3_ID, EB_FILL_ALL));
  60.       EB_AddLastSon(b1, EB_CreateHorizFill(GadCon, TRUE, 0));
  61.       EB_AddLastSon(b1, EB_CreateTextAction(GadCon, "_Push Me", GAD_1_ID, EB_FILL_ALL));
  62.       EB_AddLastSon(b1, EB_CreateHorizFill(GadCon, TRUE, 0));
  63.  
  64.       EB_AddLastSon(root, EB_CreateVertiFill(GadCon, TRUE, 0));
  65.  
  66.       b2 = EB_CreateHorizBox(GadCon);
  67.       EB_AddLastSon(root, b2);
  68.       EB_AddLastSon(b2, EB_CreateHorizFill(GadCon, TRUE, 0));
  69.       EB_AddLastSon(b2, EB_CreateTextAction(GadCon, "_Push Me", GAD_1_ID, EB_FILL_ALL));
  70.       EB_AddLastSon(b2, EB_CreateHorizFill(GadCon, TRUE, 0));
  71.       EB_AddLastSon(b2, EB_CreateTextAction(GadCon, "_Leave Me Alone", GAD_2_ID, EB_FILL_ALL));
  72.       EB_AddLastSon(b2, EB_CreateHorizFill(GadCon, TRUE, 0));
  73.       EB_AddLastSon(b2, EB_CreateTextAction(GadCon, "_Help Me", GAD_3_ID, EB_FILL_ALL));
  74.       EB_AddLastSon(b2, EB_CreateHorizFill(GadCon, TRUE, 0));
  75.  
  76.       EB_AddLastSon(root, EB_CreateVertiFill(GadCon, TRUE, 0));
  77.  
  78.       b3 = EB_CreateHorizBox(GadCon);
  79.       EB_AddLastSon(root, b3);
  80.       EB_AddLastSon(b3, EB_CreateHorizFill(GadCon, TRUE, 0));
  81.       EB_AddLastSon(b3, EB_CreateTextAction(GadCon, "_Help Me", GAD_3_ID, EB_FILL_ALL));
  82.       EB_AddLastSon(b3, EB_CreateHorizFill(GadCon, TRUE, 0));
  83.       EB_AddLastSon(b3, EB_CreateTextAction(GadCon, "_Push Me", GAD_1_ID, EB_FILL_ALL));
  84.       EB_AddLastSon(b3, EB_CreateHorizFill(GadCon, TRUE, 0));
  85.       EB_AddLastSon(b3, EB_CreateTextAction(GadCon, "_Leave Me Alone", GAD_2_ID, EB_FILL_ALL));
  86.       EB_AddLastSon(b3, EB_CreateHorizFill(GadCon, TRUE, 0));
  87.  
  88.       EB_AddLastSon(root, EB_CreateVertiFill(GadCon, TRUE, 0));
  89.  
  90.       root = EB_CreateMasterWindow(GadCon, Win, root);
  91.  
  92.       if (EB_ProcessGadBoxes(GadCon, root))
  93.         {
  94.          ret = 1;
  95.         }
  96.      }
  97.  
  98.    return ret;
  99. }
  100.  
  101. BYTE  CreateWindow(void)
  102. {
  103.    BYTE  ret = 0;
  104.  
  105.    if (CreateGfx())
  106.      {
  107.       GadCon->NewWin->Title              = "EGS Gadget Demo 5";
  108.       GadCon->NewWin->Flags             &= ~EI_SMART_REFRESH;
  109.       GadCon->NewWin->Flags             |= (EI_SIZEBBOTTOM | EI_WINDOWCENTER);
  110.       GadCon->NewWin->IDCMPFlags        |= (EI_iCLOSEWINDOW | EI_iGADGETUP | EI_iSIZEVERIFY | EI_iNEWSIZE);
  111.       GadCon->NewWin->Bordef.SysGadgets |= (EI_WINDOWCLOSE | EI_WINDOWSIZE);
  112.       if (Win = EI_OpenWindow(GadCon->NewWin))
  113.         {
  114.          ret = 1;
  115.         }
  116.      }
  117.  
  118.    return ret;
  119. }
  120.  
  121. main()
  122. {
  123.    struct EI_EIntuiMsg  *IMsg;
  124.    struct EI_Gadget     *TempGad;
  125.    BYTE  quit = 0;
  126.  
  127.    if (EGSIntuiBase = OpenLibrary("egsintui.library", 0))
  128.      {
  129.       if (EGBBase = OpenLibrary("egsgadbox.library", 0))
  130.         {
  131.          if (CreateWindow())
  132.            {
  133.             while (!quit)
  134.               {
  135.                WaitPort(Win->UserPort);
  136.                if (IMsg = (struct EI_EIntuiMsg *)GetMsg(Win->UserPort))
  137.                  {
  138.                   if (IMsg->Class == EI_iCLOSEWINDOW)
  139.                     {
  140.                      quit = 1;
  141.                     }
  142.                   if (IMsg->Class == EI_iGADGETUP)
  143.                     {
  144.                      TempGad = (struct EI_Gadget *)IMsg->IAddress;
  145.                      if (TempGad->GadgetID == GAD_1_ID)
  146.                        {
  147.                         printf("You pressed me!\n");
  148.                        }
  149.                      if (TempGad->GadgetID == GAD_2_ID)
  150.                        {
  151.                         printf("You're not leaving me alone!\n");
  152.                        }
  153.                      if (TempGad->GadgetID == GAD_3_ID)
  154.                        {
  155.                         printf("You helped me!\n");
  156.                        }
  157.                     }
  158.                   if (IMsg->Class == EI_iSIZEVERIFY)
  159.                     {
  160.                      EI_RemoveGList(Win, GadCon->First, GadCon->Num);
  161.                      EB_DeleteGadContext(GadCon);
  162.                      GadCon = NULL;
  163.                     }
  164.                   if (IMsg->Class == EI_iNEWSIZE)
  165.                     {
  166.                      EI_LockIntuition();
  167.                      CreateGfx();
  168.                      if (GadCon)
  169.                        {
  170.                         EI_AddGList(Win, GadCon->First, GadCon->Num);
  171.                        }
  172.                      EI_UnlockIntuition();
  173.                     }
  174.                   ReplyMsg((struct Message *)IMsg);
  175.                  }
  176.               }
  177.            }
  178.          if (Win) EI_CloseWindow(Win);
  179.          if (GadCon) EB_DeleteGadContext(GadCon);
  180.          CloseLibrary(EGBBase);
  181.         }
  182.       CloseLibrary(EGSIntuiBase);
  183.      }
  184. }
  185.